<?php 

class Event_CommentPreDelete extends Crud_Event_Handler
{
	protected $_type = 'preDelete';
	
	/**
	 * Run handler with options array.
	 * 
	 * @param OrdersRow $row
	 * @return void
	 */
	public function run($row)
	{
		//
		$id_comment = $this->_getParam('id');
		Comment2blogMessagePeer::getInstance()->delete('comment_id = '.$id_comment);
		$parent_comment = BlogCommentPeer::getInstance()->fetchRow('id = '.$id_comment);

		$child_comment = BlogCommentPeer::getInstance()->fetchAll("parent_path LIKE '".$parent_comment['parent_path']."%'");
		foreach ($child_comment as $child){
			Comment2blogMessagePeer::getInstance()->delete('comment_id = '.$child['id']);
		}
		//$query = "DELETE FROM comment2blog_message WHERE comment_id = (SELECT id FROM blog_comment WHERE parent_path LIKE '".$parent_comment['parent_path']."%' )";


		BlogCommentPeer::getInstance()->delete("parent_path LIKE '".$parent_comment['parent_path']."%'");
	}
}
